<?php
namespace app\custom\model;
use app\tools\upload\UploadQN;
use think\Validate;
use think\Db;
use app\base\model\Base;
class MsgM extends Base
{

    protected function _V($scene,$data)
    {
        $rule = [
            'type' => 'require|number',
            'name' => 'require',
            'linksrc' => 'require|url',
            'sort_num' => 'require|number',
        ];
        $msg = [];
        $field = [
            'type'=>'轮播图分类',
            'name'=>'轮播图名称',
            'linksrc'=>'链接地址',
            'sort_num'=>'排序',
        ];
        $validate = new Validate($rule,$msg,$field);
        $validate->scene('add', ['type','name','linksrc','sort_num']);
        $validate->scene('edit', ['type','name','linksrc','sort_num']);
        $result = $validate->scene($scene)->check($data);
        if($result === false)
        {
            return $validate->getError();
        }
        else
        {
            return true;
        }

    }


    /**
     * 全部数据
     */
    public function lst($page = 15)
    {
        $data = Db::table('custom_msg')->where('is_usable',1)->paginate($page);
        return $data;
    }


    /**
     * 删除数据
     * @param $id
     */
    public function del($id)
    {
        return Db::table('custom_msg')->where('id',$id)->update(['is_usable'=>0]);
    }

    /**
     * 处理消息
     * @param $id
     */
    public function handle($id)
    {
        $admin_id = session('admin_id');
        return Db::table('custom_msg')->where('id',$id)->update(['is_handle'=>1,'admin_id'=>$admin_id,'handle_at'=>time()]);
    }

}
